//
//  BBHomeBezierView.m
//  BlockBrowser
//
//  Created by Mac on 2018/3/29.
//  Copyright © 2018年 stoneobs@icloud.com. All rights reserved.
//

#import "BBHomeBezierView.h"
@interface BBHomeBezierView()
@property(nonatomic, strong) UIBezierPath                     *movePath;
@property(nonatomic, strong) CAShapeLayer                     *shapeLayer;
@end
@implementation BBHomeBezierView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = TM_ThemeBackGroundColor;
        [self configSubView];
    }
    return self;
}
#pragma mark --subView
- (void)configSubView{
    self.movePath = [UIBezierPath bezierPath];
    [self updateLayer];
    
}
- (void)updateLayer{
    if (!_shapeLayer) {
        _shapeLayer = [CAShapeLayer layer];
    }else{
        [_shapeLayer removeFromSuperlayer];
    }
    _shapeLayer.frame = self.bounds;
    _shapeLayer.fillColor = TM_ThemeBackGroundColor.CGColor;
    _shapeLayer.lineWidth = 1.0f;
    _shapeLayer.strokeColor = [UIColor clearColor].CGColor;
    _shapeLayer.path = self.movePath.CGPath;
    [self.layer addSublayer:_shapeLayer];
}
- (void)updateWithY:(CGFloat)y{
    [_movePath removeAllPoints];
    CGFloat height = self.height - 1;
    CGPoint point = CGPointMake(UIScreenWidth / 2, 2.0 * y + height);
    [_movePath moveToPoint:CGPointMake(0, height)];
    [_movePath addLineToPoint:CGPointMake(self.width, height)];
    [_movePath addQuadCurveToPoint:CGPointMake(0, self.height) controlPoint:point];
    [self updateLayer];
}
@end
